package com.easydisk.file.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.easydisk.file.model.entity.UploadFile;
import com.easydisk.file.model.req.FileChunkCheckReq;
import com.easydisk.file.model.vo.CheckFileChunkUploadVO;
import com.easydisk.file.model.vo.FileChunkUploadVO;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * <p>
 * 物理文件信息表 服务类
 * </p>
 *
 * @author word
 * @since 2023-09-08
 */
public interface UploadFileService extends IService<UploadFile> {

    String getUrlPath(String bucket, String objectKey);

    /**
     * 上传文件
     * @param file       文件内容
     * @param parentId   文件父id
     * @param userId     用户标识
     * @param identifier md5 唯一标识
     * @param totalSize  文件大小 bytes单位
     * @param filename   文件名称 如 a.doc
     */
    void uploadFile(MultipartFile file, Long parentId, Long userId,
                    String identifier, Long totalSize, String filename);

    /**
     * 根据文件id查找
     */
    UploadFile getById(Long fileId);

    /**
     * 下载文件
     */
    void downloadFile(Long fileId, HttpServletResponse response, Long userId);

    /**
     * 下载文件(分享文件)
     */
    void downloadFile(Long fileId, HttpServletResponse response);

    /**
     * 读取文件为输入流
     */
    void read2OutputStream(String bucketName, String filePath, OutputStream outputStream) throws IOException;

    void read2OutputStream(String filePath, OutputStream outputStream);

    /**
     * 秒传
     */
    boolean secondUploadFile(Long parentId, String filename, String identifier, Long userId);

    void mergeFileChunks(String filename, String identifier, Long parentId, Long totalSize, Long userId);


    void mergeFileChunksByRedis(String filename, String identifier, Long parentId, Long totalSize, Long userId);

    void deleteFileChunkByIdentifierAndUserId(String identifier, Long userId);

    CheckFileChunkUploadVO checkUploadWithChunk(Long userId, String identifier);

    CheckFileChunkUploadVO checkUploadWithChunkByRedis(Long userId, FileChunkCheckReq fileChunkCheckReq);

    FileChunkUploadVO uploadWithChunk(MultipartFile file, Long userId, String identifier, Integer totalChunks, Integer chunkNumber, Long totalSize, String filename);

    FileChunkUploadVO uploadWithChunkByRedis(MultipartFile file, Long userId, String identifier, Integer totalChunks, Integer chunkNumber, Long totalSize, String filename);

    void physicalDeleteUserFiles(String fileIds, Long userId);


}
